package com.zhai.cloud.frame.msg.buffer.controller;

import com.zhai.cloud.common.domain.Result;
import com.zhai.cloud.common.util.BigDecimalUtil;
import com.zhai.cloud.common.util.DateUtil;
import com.zhai.cloud.common.util.JSONUtil;
import com.zhai.cloud.frame.msg.buffer.domain.BizDealSave;
import com.zhai.cloud.frame.msg.buffer.sender.BizDealSaveSender;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author Created by 翟凤玺
 * @package com.zhai.cloud.frame.msg.buffer.controller
 * @project-name zhai-cloud
 * @description 消息缓冲入口-交易业务
 * @create-datetime 2020-5-6 10:18
 */
@Api(value = "消息缓冲入口-交易业务")
@Slf4j
@RestController
@RequestMapping("/msg-buffer/biz/deal")
public class BizDealController {

    @Autowired
    BizDealSaveSender bizDealSaveSender;

    @PostMapping("/save")
    public Result save(@RequestBody BizDealSave in) {
        String serialNum = UUID.randomUUID().toString();
        in.setSerialNum(serialNum);
        Map<String, Object> headers = new HashMap<>(1);
        headers.put("zhai", "msg");
        log.info(DateUtil.fmtLocalDateTimeToStr(DateUtil.getCurrentLocalDateTime(), DateUtil.DATETIME_FMT_3) + "发送消费机时间" + "  流水号：" + in.getSerialNum());
        bizDealSaveSender.send(serialNum, JSONUtil.toStr(in), null);
        log.info(DateUtil.fmtLocalDateTimeToStr(DateUtil.getCurrentLocalDateTime(), DateUtil.DATETIME_FMT_3) + "消费机处理完成时间"+ "  流水号：" + in.getSerialNum());
        return Result.success();
    }
}